package com.yequan.work;

import org.apache.commons.lang3.time.DateUtils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;

/**
 * @author yequan
 * @date 2021/06/01 16:55
 **/
public class DateDemo {

    public static void main(String[] args) throws Exception {
//        mils2Str();
//        getMonth();
//        y();
//        t();
//        localDateDemo();
//        dateCreate();
//        getMonth1();
        date2StringYM();
    }

    public static void date2StringYM() throws Exception{
        System.out.println(DateUtil.date2StringYM(new Date()));
    }

    public static void getMonth1() throws Exception {
        System.out.println(getMonth(new Date()));
    }

    public static Integer getMonth(Date planStartTime) {
        return DateUtil.get(planStartTime, Calendar.MONTH) + 1;
    }

    public static void dateCreate() throws Exception {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        Date date = dateFormat.parse("20220121082100");
        System.out.println(date.before(new Date()));
    }

    public static void localDateDemo() {
        LocalDate localDate = Instant.ofEpochMilli(Long.parseLong("1587975761000")).atZone(ZoneId.systemDefault()).toLocalDate();
        if (localDate.equals(LocalDate.now())) {
            System.out.println("jjjjj");
        }
    }

    public static void t() throws Exception {
        Date date = DateUtil.String2Date3("2021-09-16 15:25:00");
        long time = date.getTime();
        System.out.println(time);
        System.out.println(System.currentTimeMillis());
        if (time - System.currentTimeMillis() > 15 * 60000L) {
            System.out.println("llll");
            Date startAtTime = DateUtil.addDateField(date, -15, Calendar.MINUTE);
            System.out.println(DateUtil.date2String2(startAtTime));
        }
    }

    public static void y() {
        Calendar workCalendar = Calendar.getInstance();
        workCalendar.setTime(new Date(44400000));
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.set(Calendar.HOUR_OF_DAY, workCalendar.get(Calendar.HOUR));
        calendar.set(Calendar.MINUTE, workCalendar.get(Calendar.MINUTE));
        calendar.set(Calendar.SECOND, 0);
        System.out.println(calendar.getTime().getTime() / 1000);

        Date now = new Date();
        System.out.println(now.getTime());
        System.out.println(DateUtil.getSpecificTime(DateUtils.addDays(now, 30), 23, 59, 59, 0).getTime());
    }

    public static void mils2Str() throws Exception {
        System.out.println(DateUtil.date2String(new Date(1897812343000L)));
        System.out.println(DateUtil.date2String(new Date(1574870399000L)));
        System.out.println(DateUtil.date2String(new Date(1574870399000L)));
    }

    public static void getMonth() throws Exception {
        Date planStartTime = DateUtil.string2DateYM("202108");
//        int month = DateUtil.get(new Date(), Calendar.MONTH);
        int month = DateUtil.get(planStartTime, Calendar.MONTH) + 1;
        System.out.println(month);
    }

}
